/* 
 * Created on 2007-2-7
 * Last modified on 2007-2-7
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.commons.util;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class HttpServletUtils {

	private static final Logger logger = Logger.getLogger(HttpServletUtils.class);

	public static void forward(HttpServletRequest request, HttpServletResponse response, String url) {
		if (ValidatorHelper.isEmpty(response) 
				|| ValidatorHelper.isEmpty(request) 
				|| ValidatorHelper.isEmpty(url)) 
		{
			return;
		}
		try {
			request.getRequestDispatcher(url).forward(request, response);
		} catch (ServletException e) {
			logger.error(e.toString());
		} catch (IOException e) {
			logger.error(e.toString());
		} catch (RuntimeException e) {
			logger.error(e.toString());
		}
	}

	public static void redirect(HttpServletResponse response, String url) {
		if (ValidatorHelper.isEmpty(response) || ValidatorHelper.isEmpty(url)) {
			return;
		}
		try {
			response.sendRedirect(url);
		} catch (IOException e) {
			logger.error(e.toString());
		} catch (RuntimeException e) {
			logger.error(e.toString());
		}
	}
}
